﻿using Edge_tts_sharp;
using Edge_tts_sharp.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/**
 * sparkok改造
 * 功能:启动edge浏览器,并对它进行内录
 * https://github.com/fysh711426/EdgeTTS
 */
namespace txt_file_reader
{
    class MicrosoftTts
    {
        static bool init = false;
        private static eVoice voice = null;

        static public bool ConvertTxt2Voice(string text, string tmpMp3Path)
        {
            //可以使用
            //参考文档：https://github.com/fysh711426/EdgeTTS
            try
            {
                // 1.0
                //Edge_tts.PlayText(msg, "zh-CN", "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)", "webm-24khz-16bit-mono-opus");
                if (MicrosoftTts.voice == null)
                {
                    //MicrosoftTts.voice = Edge_tts.GetVoice().FirstOrDefault(i => i.Name == "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)");
                    MicrosoftTts.voice = Edge_tts.GetVoice().FirstOrDefault(i => i.Name == "Microsoft Server Speech Text to Speech Voice (zh-CN, YunyangNeural)");
                }
                
                Edge_tts.PlayOrSave(text, MicrosoftTts.voice, 0, tmpMp3Path);
                return true;
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
                return false;
            }
        }
    }
}
